﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace Sharp.Portal.Mvc.Form
{
    /// <summary>
    /// 字段小节
    /// </summary>
    public class FormSection
    {
        /// <summary>
        /// 表单小节类构造函数
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="iFrameUri">iFrame 链接，当这个参数不为空时，禁止加入子元素</param>
        public FormSection(string title, string iFrameUri = "")
        {
            this.Title = title;
            //Items = new ArrayList();
            //Style = FormFieldStyle.Section;
            this.IFrameUri = iFrameUri;
            this.Fields = new List<FieldItem>();
        }
        /// <summary>
        /// iFrame 链接
        /// </summary>
        public string IFrameUri { get; set; }

        /// <summary>
        /// 内置字段列表
        /// </summary>
        public IList<FieldItem> Fields { get; set; }
        public string Title { get; set; }
        public string Path { get; internal set; }
        public string ItemsFromAction { get; set; }
        public string RouteValues { get; set; }

        /// <summary>
        /// 增加子元素
        /// </summary>
        /// <param name="item">元素</param>
        public void AddElement(FieldItem item)
        {
            if (!this.IFrameUri.IsNullOrEmpty())
            {
                throw new Exception("iFrame 链接不为空，禁止加入子元素");
            }

            //if (item.IsCanShow())//是否有权限显示
            {
                this.Fields.Add(item);
            }
        }
    }
}